package com.feisuanyz.controller;

import com.feisuanyz.dto.RestResult;
import com.feisuanyz.dto.TicketQuery;
import com.feisuanyz.service.TicketService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tickets")
@Slf4j
public class TicketController {

    @Autowired
    private TicketService ticketService;

    @PostMapping("/create")
    public ResponseEntity<RestResult<Void>> createTicket(@Valid @RequestBody TicketQuery ticketQuery) {
        RestResult<Void> result = ticketService.createTicket(ticketQuery);
        return ResponseEntity.ok(result);
    }

    @PutMapping("/edit")
    public ResponseEntity<RestResult<Void>> editTicket(@Valid @RequestBody TicketQuery ticketQuery) {
        RestResult<Void> result = ticketService.editTicket(ticketQuery);
        return ResponseEntity.ok(result);
    }

    @DeleteMapping("/delete/{ticketId}")
    public ResponseEntity<RestResult<Void>> deleteTicket(@PathVariable Integer ticketId, @RequestParam Integer deleteBy) {
        RestResult<Void> result = ticketService.deleteTicket(ticketId, deleteBy);
        return ResponseEntity.ok(result);
    }
}